﻿using SFJDService;
using System;
using System.Diagnostics;
using System.Windows.Forms;

namespace SFJDTray
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            new SFJDRun();
        }

        private void OpenManagement()
        {
            try
            {
                bool isStarted = false;
                Process[] pro = Process.GetProcesses();//获取已开启的所有进程
                for (int i = 0; i < pro.Length; i++)//遍历所有查找到的进程
                {
                    //判断此进程是否是要查找的进程
                    if (pro[i].ProcessName.ToString().ToLower() == "sfjdmanagement")
                    {
                        isStarted = true;
                        break;
                    }
                }
                if (!isStarted)
                {
                    Process p = new Process();
                    p.StartInfo.FileName = Runtime.programPath + "\\SFJDManagement.exe";
                    p.Start();
                }
            }
            catch(Exception e)
            {
                Runtime.Printf(e.StackTrace);
            }
        }

        private void 主程序ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenManagement();
        }

        private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
        {
            switch (e.Button)
            {
                case MouseButtons.Left://左键点击图标
                    OpenManagement();
                    break;
                //case MouseButtons.Right://右键点击图标
                //    //ShowRight(e.X, e.Y);
                //    notifyIcon1.ShowBalloonTip(20000, "通知", "000000", ToolTipIcon.Info);
                //    break;
            }
        }

        private void 调试程序ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Runtime.DebugWindowSwitch();
        }

        private void Form1_VisibleChanged(object sender, EventArgs e)
        {
            if(Visible == true)
            {
                Visible = false;
            }
        }
    }
}
